﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BomberManServer.Gaming.Object;
using BomberManServer.Gaming;

namespace BomberManServer.Gaming.Object.Stats
{
    public abstract class GameStats
    {
        public Match.MatchType gameType { get; private set; }
        public TeamStats[] teamStats { get; private set; }
        public ushort game_id { get; private set; }
        public int nbRound;
        public UInt32 ffa_WinnerID;

        public GameStats(Match match)
        {
            this.teamStats = new TeamStats[match.teams.Count];
            this.game_id = match.uid;

            this.gameType = match.type;
            foreach (Team team in match.teams)
            {
                this.teamStats[team.id] = new TeamStats(team);
                foreach (Player player in team.players)
                {
                    this.teamStats[team.id].players.Add(new PlayerStats(player.uid, team.id));
                }
            }
            this.nbRound = 0;
            this.ffa_WinnerID = 0;
        }

        public abstract Int16 getScore(UInt16 team_id);

        public abstract UInt16 getWinnerID();

        public TeamStats getTeam(UInt16 id)
        {
            foreach (TeamStats team in teamStats)
                if (team.teamID == id)
                    return team;
            return null;
        }

        public PlayerStats getPlayer(UInt32 uid)
        {
            foreach (TeamStats team in teamStats)
                foreach (PlayerStats player in team.players)
                    if (player.uid == uid)
                        return player;
            return null;
        }

    }
}
